import logo from './logo.svg';
import { Button } from 'antd';
import './App.css';
import {HashRouter as Router, Route, Link, Switch, Redirect} from 'react-router-dom'
import {adminRoutes} from "./routes";
import React from "react";
import Frame from "./components/Frame";


function getRoute(routes) {
    let arr = []
    for (let i = 0; i < routes.length; i++) {
        if (routes[i]['path']){
            arr.push(routes[i])
        }else if (routes[i]['children'] && routes[i]['children'].length>0){
            for (let j = 0; j < routes[i]['children'].length; j++) {
                if ( routes[i]['children'][j]['path']){
                    arr.push(routes[i]['children'][j])
                }
            }
        }
    }
    return arr;
}

function App(props) {
    return (
        <Frame {...props}>
            <div className="App">
                <Switch>
                    {
                        getRoute(adminRoutes).map(route => {
                            return <Route key={route.path}  {...route}  />
                        })
                    }
                    {<Redirect to="/404" />}
                </Switch>
            </div>
        </Frame>
    );
}

export default App;
